﻿
using CSharpLibs.Annotations;

namespace System.IO
{
	[Builtin]
	public abstract class TextWriter : Object, IDisposable
	{
		public virtual void Close()
		{ ;}

		public void Dispose()
		{ this.Close(); }

		public virtual void Flush()
		{ ;}

		public virtual void Write(char[] buffer)
		{
			if(buffer != null)
				this.Write(buffer, 0, buffer.Length);
		}

		public virtual void Write(bool value)
		{ this.WriteStringInternal(value ? "true" : "false"); }

		public virtual void Write(char value)
		{ ;}

		public virtual void Write(double value)
		{ this.WriteStringInternal(value.ToString()); }

		public virtual void Write(int value)
		{ this.WriteStringInternal(value.ToString()); }

		public virtual void Write(long value)
		{ this.WriteStringInternal(value.ToString()); }

		public virtual void Write(object o)
		{
			if(o == null)
				this.WriteStringInternal("null");
			else
				this.Write(o.ToString());
		}

		public virtual void Write(float value)
		{ this.WriteStringInternal(value.ToString()); }

		public virtual void Write(string s)
		{
			for(int i = 0; i < s.Length; ++i)
				this.Write(s[i]);
		}

		public virtual void WriteStringInternal(string s)
		{
			for(int i = 0; i < s.Length; ++i)
				this.Write(s[i]);
		}

		public virtual void Write(char[] buffer, int index, int count)
		{
			for(int i = 0; i < count; i++)
				this.Write(buffer[index + i]);
		}

		public virtual void WriteLine()
		{
			this.WriteStringInternal("\r\n");
		}

		public virtual void WriteLine(char[] buffer)
		{
			this.Write(buffer);
			this.WriteLine();
		}

		public virtual void WriteLine(bool value)
		{
			this.Write(value);
			this.WriteLine();
		}

		public virtual void WriteLine(char value)
		{
			this.Write(value);
			this.WriteLine();
		}

		public virtual void WriteLine(double value)
		{
			this.Write(value);
			this.WriteLine();
		}

		public virtual void WriteLine(int value)
		{
			this.Write(value);
			this.WriteLine();
		}

		public virtual void WriteLine(long value)
		{
			this.Write(value);
			this.WriteLine();
		}

		public virtual void WriteLine(object value)
		{
			this.Write(value);
			this.WriteLine();
		}

		public virtual void WriteLine(float value)
		{
			this.Write(value);
			this.WriteLine();
		}

		public virtual void WriteLine(string value)
		{
			this.Write(value);
			this.WriteLine();
		}

		public virtual void WriteLine(char[] buffer, int index, int count)
		{
			this.Write(buffer, index, count);
			this.WriteLine();
		}
	}
}
